{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import librosa\n",
    "import numpy as np\n",
    "import torch\n",
    "from torchaudio import transforms"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "wav_array, _ = librosa.load('./VCTK/p225/p225_001.wav', sr=16000, mono=True)\n",
    "wav_array, _ = librosa.effects.trim(wav_array, top_db=10, frame_length=2048)\n",
    "# remove trim, leading and trailing silence.\n",
    "wav_tensor = torch.from_numpy(wav_array)\n",
    "wav_tensor = transforms.MuLawEncoding()(wav_tensor).unsqueeze(0)\n",
    "# map values from [-1, 1] to [0, 255]\n",
    "np.save('wav.npy', wav_tensor.numpy())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
